package com.skyworth.skymanualdata;
import java.util.ArrayList;
import java.util.HashMap;
import com.skyworth.skymanualActivity.GuideListActivity;
import com.skyworth.skymanual.R;
import android.content.Context;
import android.graphics.Color;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;
public class DataAdapter extends BaseAdapter {
	private LayoutInflater mInflater;
	private ArrayList<HashMap<String, Object>> list;
	private static HashMap<Integer, Boolean> isSelected;
	private int[] title_position={};
	private int title_position_id=0;
	TextView[] mytext = new TextView[7];
	private String[] key;
	private int color;
	private int type_text;
	private int title_color=Color.WHITE,secondtitle_color=Color.WHITE,context_color=Color.WHITE;
	
	public DataAdapter(Context context,ArrayList<HashMap<String, Object>> list, String[] key,int color,int[] title_position,int type_text) {
		this.list = list;
		this.key = key;
		this.type_text=type_text;
		this.color = color;
		this.title_position=title_position;
		mInflater = LayoutInflater.from(context);
		isSelected = new HashMap<Integer, Boolean>();
		initDate();
	}
	
	private void initDate() {
		for (int i = 0; i < list.size(); i++) {
			getIsSelected().put(i, false);
		}
	}
	

	public DataAdapter(Context context) {

		this.mInflater = LayoutInflater.from(context);
	}
	

	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return list.size();
	}

	@Override
	public Object getItem(int position) {
		// TODO Auto-generated method stub
		return list.get(position);
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return position;
	}
	
	@Override
	public View getView( int position, View convertView, ViewGroup arg2) {
		// TODO Auto-generated method stub
		if (convertView == null) 
		{				
			if(type_text==1){
			   convertView = mInflater.inflate(R.layout.content_text_list, null);
			   mytext[0] = (TextView) convertView.findViewById(R.id.text11);
		       mytext[1] = (TextView) convertView.findViewById(R.id.text12);
		       mytext[2] = (TextView) convertView.findViewById(R.id.text13);
			   mytext[3] = (TextView) convertView.findViewById(R.id.text14);
			   mytext[4] = (TextView) convertView.findViewById(R.id.text15);
			   mytext[5] = (TextView) convertView.findViewById(R.id.text16);
			   mytext[6] = (TextView) convertView.findViewById(R.id.text17);			   
			   title_color=Color.WHITE;
			   secondtitle_color=0x77ffffff;
			   context_color=Color.WHITE;
			   
			}else if(type_text==2){
				convertView = mInflater.inflate(R.layout.only_text_list, null);					
				mytext[0] = (TextView) convertView.findViewById(R.id.text21);
				mytext[1] = (TextView) convertView.findViewById(R.id.text22);
				mytext[2] = (TextView) convertView.findViewById(R.id.text23);
				mytext[3] = (TextView) convertView.findViewById(R.id.text24);
				mytext[4] = (TextView) convertView.findViewById(R.id.text25);
				mytext[5] = (TextView) convertView.findViewById(R.id.text26);
				mytext[6] = (TextView) convertView.findViewById(R.id.text27);
				
				title_color=Color.BLACK;
				secondtitle_color=Color.BLACK;
				context_color=0xaa000000;
			}
			
			
		} 
	
		
		String str = list.get(position).get("ItemText").toString();
		String[] strarray = str.split("'");
		for (int i = 0; i < strarray.length; i ++)
		{			
			mytext[7 - strarray.length + i].setText(strarray[i]);
			
			if(title_position_id<title_position.length){
				if(title_position[title_position_id]==-1){
					if(position==title_position_id){
						mytext[7 - strarray.length + i].setTextSize(70*GuideListActivity.DIV_W/GuideListActivity.density);
						mytext[7 - strarray.length + i].setTextColor(title_color);
					}
				}
				if(title_position[title_position_id]==0){
					if(position==title_position_id){
						mytext[7 - strarray.length + i].setTextSize(40*GuideListActivity.DIV_W/GuideListActivity.density);
						mytext[7 - strarray.length + i].setTextColor(context_color);
					}
				}
				
				if(title_position[title_position_id]==1){
					if(position==title_position_id){
						mytext[7 - strarray.length + i].setTextSize(50*GuideListActivity.DIV_W/GuideListActivity.density);
						mytext[7 - strarray.length + i].setTextColor(secondtitle_color);
					}
				}
			}else{
					mytext[7 - strarray.length + i].setTextSize(40/GuideListActivity.DIV_W/GuideListActivity.density);
					mytext[7 - strarray.length + i].setTextColor(context_color);
			     
			}
			
			
		title_position_id++;

			if(strarray.length > 1)
			{
				for (int j = 0; j < key.length; j ++)
				{
					
					if(strarray[i].equals(key[j]))
					{
						mytext[7 - strarray.length + i].setTextColor(color);
						mytext[7 - strarray.length + i].setTextSize(40*GuideListActivity.DIV_W/GuideListActivity.density);
					}else{
						mytext[7 - strarray.length + i].setTextSize(40*GuideListActivity.DIV_W/GuideListActivity.density);
					}
					
				}
			}
			
		}
		
		return convertView;
	}
	
	public static HashMap<Integer, Boolean> getIsSelected() {
		return isSelected;
	}
	
	public static void setIsSelected(HashMap<Integer, Boolean> isSelected) {
		DataAdapter.isSelected = isSelected;
	}

}